package com.nj.api.web.controller;

import com.nj.api.entity.Product;
import com.nj.api.service.ProductService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("product")
@CrossOrigin //允许跨域请求
public class ProductController {
    @Resource
    private ProductService productService;


    @GetMapping("rate")
    public Object getRate(){
        return productService.getRate();
    }
    @GetMapping("/index")
    public Map index(){
    
        return new HashMap(){{
           put("new",productService.getNew());
           put("yxs",productService.getYx());
           put("sbs",productService.getSb());
        }};
    }
    @GetMapping("list/{type}")
    public List<Product> index(@PathVariable String type){
        return productService.getByType(type);
    }
    @GetMapping("top3")
    public List top3(){
        return productService.getTop3();
    }
    @GetMapping("/{id}")
    public Product getProductById(@PathVariable Long id){
        return productService.getById(id);
    }
}
